﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace intelliEssay.Interop
{
    /// <summary>
    /// Key_Priority_Pair is a type that is used to represent a Value and its priority in comparison with other Value_Priority_Pair
    /// The higher the priority's value is, the lower the priority when partcipated in a merge operation.
    /// <para>in other word, the element with lower priority value will Supercede the element with hIGHER priority value</para>
    /// </summary>
    /// <remarks>
    /// Value_Priority_Pair is quite useful when resolving priorities of ParagraphProperties elements and RunProperties elements.
    /// </remarks>
    public struct Value_Priority_Pair : IComparable<Value_Priority_Pair>, IComparable
    {
        /// <summary>
        /// The value to be stored in this pair
        /// </summary>
        public dynamic value;
        /// <summary>
        /// The priority of the pair, LOWER the more important
        /// </summary>
        public double priority;
        /// <summary>
        /// Comparing 2 V_P_P elements, and return the result
        /// </summary>
        /// <param name="w"></param>
        /// <returns>1 if larger, -1 if smaller, 0 if equal</returns>
        public int CompareTo(Value_Priority_Pair w)
        {
            if (priority > w.priority)
            {
                return -1;
            }
            if (priority == w.priority)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }
        /// <summary>
        /// if the object o is type of V_P_P, it is same to CompareTo, otherwise the method fails
        /// <see cref="intelliEssay.Core.Value_Priority_Pair.CompareTo(intelliEssay.Core.Value_Priority_Pair)"/>
        /// </summary>
        /// <param name="o"></param>
        /// <returns>the same as CompareTo</returns>
        public int CompareTo(object o)
        {
            if (o is Value_Priority_Pair)
            {
                return this.CompareTo((Value_Priority_Pair)o);
            }
            throw new Exception();
        }
    }
}
